import numpy as np
import pandas as pd
df = pd.read_excel('stock.xlsx', dtype={'code':'str'})
year = df.timeToMarket.astype('str').str[:4]  # 转换为字符串，提取前4位的年份
yearnum = df.groupby(year).name.count()
df.pe.mean()
df['tvalue'] = 4 * df.esp - df.pe * df.totals
print(np.sum(df.pe*df.tvalue) / df.tvalue.sum())